<?php
include('../classess/scheduled_trainee.php');
$scheduled_trainee = new scheduled_trainee();
include('../classess/add_schedule.php');
$trainer_free_slot = new add_schedule();

if (isset($_POST['get_course']) && $_POST['get_course'] != '') {
    $student_id = $_POST['student_id'];
    $course_array = $scheduled_trainee->course_array($student_id);
    $string = "<option value=''>Select Course</option>";
    foreach ($course_array as $s_key => $s_value){
        $string .= "<option value='".$s_key."'>".$s_value."</option>";
    }
    echo $string;
}


if (isset($_POST['get_student_email']) && $_POST['get_student_email'] != '') {
    $student_id = $_POST['student_id'];
    $student_array = $scheduled_trainee->student_array();
    foreach ($student_array as $s_key => $s_value){
        if($s_key == $student_id ){
            echo $s_value['email'];
        }
    }
}

if (isset($_POST['get_traniee']) && $_POST['get_traniee'] != '') {
    $course_id = $_POST['course_id'];
    $traniee_array = $scheduled_trainee->traniee_array($course_id);
    $string = "<option value=''>Select Trainer</option>";
    foreach ($traniee_array as $s_key => $s_value){
        $string .= "<option value='".$s_key."'>".$s_value."</option>";
    }
    echo $string;
}

if (isset($_POST['trainer_finish_course']) && $_POST['trainer_finish_course'] != ''){
   $trainer_schedule_id = $_POST['trainer_schedule_id'];
   $user_id = $_POST['user_id'];
   $sql = mysql_query("update tbl_trainee_schedule set finish = 1 where id = ".$trainer_schedule_id."");
   $sql_user = mysql_query("update tbl_user set is_active = 0 where id = ".$user_id."");
   $sql1 = mysql_query("update tbl_trainee_schedule set reschedule = 0 where id = ".$trainer_schedule_id."");
   
   /*$sql_user_detail = mysql_query("select * from tbl_user where id = ".$user_id." ");
   $result_user_detail = mysql_fetch_assoc($sql_user_detail);
   */
   $select_course = " select a.username,a.email,c.`course_name`,e.finish,e.reschedule,e.id as trainer_schedule_id,a.id as user_id,a.* 
                        from tbl_user as a
                        Left JOIN `tbl_user_details` as b ON a.id = b.`user_id`
                        LEFT JOIN `tbl_courses` AS c ON c.id = b.`course_id`
                        LEFT JOIN `tbl_cart_payment` AS d ON a.id = d.`user_id`
                        LEFT JOIN tbl_trainee_schedule as e on e.`student_id` = b.id
                        WHERE  e.`id` = '".$trainer_schedule_id."' 
                        group by e.`id`  ";
    $result_user_detail = mysql_fetch_assoc(mysql_query($select_course));
    
    $username = $result_user_detail['username'];
    $course_name = $result_user_detail['course_name'];
    ob_start();
    include_once('../../mailtemplate/course_finish.php');
    $mail_body = ob_get_contents();
    ob_end_clean();
    
    $mail_to=$result_user_detail['email'];
    $mail_subject="Course Completed";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From:RV Training<info@rvtraining.net>' . "\r\n";
    mail($mail_to,$mail_subject,$mail_body, $headers);

    $mail_to = 'Vipin7477@gmail.com';
    $mail_subject="Course Completed";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From:RV Training<info@rvtraining.net>' . "\r\n";
    mail($mail_to,$mail_subject,$mail_body, $headers);
                        
                        
                        
                        
   return 1;
}

if (isset($_POST['trainer_reschedule_course']) && $_POST['trainer_reschedule_course'] != ''){
   $trainer_schedule_id = $_POST['trainer_schedule_id'];
   $user_id = $_POST['user_id'];
   $sql = mysql_query("update tbl_trainee_schedule set reschedule = 1 where id = ".$trainer_schedule_id."");
   $sql_user = mysql_query("update tbl_user set is_active = 1 where id = ".$user_id."");
   $sql1 = mysql_query("update tbl_trainee_schedule set finish = 0 where id = ".$trainer_schedule_id."");
   $select_course = " select a.username,a.email,c.`course_name`,e.finish,e.reschedule,e.id as trainer_schedule_id,a.id as user_id,a.* 
                        from tbl_user as a
                        Left JOIN `tbl_user_details` as b ON a.id = b.`user_id`
                        LEFT JOIN `tbl_courses` AS c ON c.id = b.`course_id`
                        LEFT JOIN `tbl_cart_payment` AS d ON a.id = d.`user_id`
                        LEFT JOIN tbl_trainee_schedule as e on e.`student_id` = b.id
                        WHERE  e.`id` = '".$trainer_schedule_id."' 
                        group by e.`id`  ";
    $result_user_detail = mysql_fetch_assoc(mysql_query($select_course));
    
    $username = $result_user_detail['username'];
    $course_name = $result_user_detail['course_name'];
    ob_start();
    include_once('../../mailtemplate/course_reschedule.php');
    $mail_body = ob_get_contents();
    ob_end_clean();
    
    $mail_to=$result_user_detail['email'];
    $mail_subject="Course Completed";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From:RV Training<info@rvtraining.net>' . "\r\n";
    mail($mail_to,$mail_subject,$mail_body, $headers);

    $mail_to = 'Vipin7477@gmail.com';
    $mail_subject="Course Completed";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From:RV Training<info@rvtraining.net>' . "\r\n";
    mail($mail_to,$mail_subject,$mail_body, $headers);
   
   return 1;
}

/*
if (isset($_POST['get_free_slot']) && $_POST['get_free_slot'] != ''){
    $data  = $trainer_free_slot->schedule_detail("where t_date = '".$_POST['date']."' and t_trainer_id = '".$_POST['trainer_id']."'");
    $finalArray = array();
    foreach($data as $_key => $_value){
        $finalArray['status'][$_key]= $_value['t_status'];
        $finalArray['t_time_solt_id'][$_key] = $_value['t_time_solt_id'];
    }
    echo json_encode($finalArray);
}
*/
?>
